package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.AjaxMessage;
import com.qfedu.openplateform.manager.entity.ApiMapping;
import com.qfedu.openplateform.manager.entity.AppInfo;
import com.qfedu.openplateform.manager.entity.TableData;
import com.qfedu.openplateform.manager.service.ApiMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/sys/api_mapping")
@RestController
public class ApiMappingController {

    @Autowired
    private ApiMappingService apiMappingService;

    @RequestMapping("/table")
    public TableData table(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<ApiMapping> apiMappingList = apiMappingService.findAll();
        PageInfo<ApiMapping> info = new PageInfo(apiMappingList);
        TableData<ApiMapping> appInfoTableData = new TableData<>(info.getTotal(), info.getList());
        return appInfoTableData;
    }

    @RequestMapping("/add")
    public AjaxMessage add(ApiMapping apiMapping) {
        apiMappingService.add(apiMapping);
        return new AjaxMessage(true, "成功");
    }

    @RequestMapping("/del")
    public AjaxMessage add(Integer[] ids) {
        apiMappingService.delete(ids);
        return new AjaxMessage(true, "成功");
    }

    @RequestMapping("/update")
    public AjaxMessage update(ApiMapping apiMapping) {
        apiMappingService.update(apiMapping);
        return new AjaxMessage(true, "成功");
    }
}
